/*
 * $Id: QEArrlData.m 34 2009-04-21 20:24:55Z jon@bway.net $
 * Sleeper
 *
 * Created by Jon Gordon on 3/17/08
 * Copyright Jon Gordon.  All rights reserved.
 * 
 * Permission is hereby granted, free of charge, to any person obtaining 
 * a copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including 
 * without limitation the rights to use, copy, modify, merge, publish, 
 * distribute, sublicense, and/or sell copies of the Software, and to 
 * permit persons to whom the Software is furnished to do so, subject to 
 * the following conditions:
 * 
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 
 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */


#import "QEArrlData.h"

#import "QEArrlSection.h"
#import "QEContestCategory.h"

#import "QEGeoData.h"
#import "QECountry.h"

static NSArray *sections = nil;
static NSArray *categories = nil;


@implementation QEArrlData
+ (void)initialize
{
   // NSLog(@"MESSAGE: %s", __PRETTY_FUNCTION__);
    static BOOL initialized = NO;
    
    if (!initialized) {
        initialized = YES;
       // NSLog(@"  initializing");
        QECountry *usa = [QECountry countryForName:@"United States"];
        QECountry *canada = [QECountry countryForName:@"Canada"];
        
        NSMutableArray *tmpSections = [[NSMutableArray alloc] init];
        
        [tmpSections addObject:[[[QEArrlSection alloc] initWithSectionName:@"Connecticut" sectionAbbr:@"CT" country:usa] autorelease]];
        [tmpSections addObject:[[[QEArrlSection alloc] initWithSectionName:@"Eastern Massachusetts" sectionAbbr:@"EMA" country:usa] autorelease]];
        [tmpSections addObject:[[[QEArrlSection alloc] initWithSectionName:@"Maine" sectionAbbr:@"ME" country:usa] autorelease]];
        [tmpSections addObject:[[[QEArrlSection alloc] initWithSectionName:@"New Hampshire" sectionAbbr:@"NH" country:usa] autorelease]];
        [tmpSections addObject:[[[QEArrlSection alloc] initWithSectionName:@"Rhode Island" sectionAbbr:@"RI" country:usa] autorelease]];
        [tmpSections addObject:[[[QEArrlSection alloc] initWithSectionName:@"Vermont" sectionAbbr:@"VT" country:usa] autorelease]];
        [tmpSections addObject:[[[QEArrlSection alloc] initWithSectionName:@"Western Massachusetts" sectionAbbr:@"WMA" country:usa] autorelease]];
        
        [tmpSections addObject:[[[QEArrlSection alloc] initWithSectionName:@"Eastern New York" sectionAbbr:@"ENY" country:usa] autorelease]];
        [tmpSections addObject:[[[QEArrlSection alloc] initWithSectionName:@"New York City-Long Island" sectionAbbr:@"NLI" country:usa] autorelease]];
        [tmpSections addObject:[[[QEArrlSection alloc] initWithSectionName:@"Northern New Jersey" sectionAbbr:@"NNJ" country:usa] autorelease]];
        [tmpSections addObject:[[[QEArrlSection alloc] initWithSectionName:@"Northern New York" sectionAbbr:@"NNY" country:usa] autorelease]];
        [tmpSections addObject:[[[QEArrlSection alloc] initWithSectionName:@"Southern New Jersey" sectionAbbr:@"SNJ" country:usa] autorelease]];
        [tmpSections addObject:[[[QEArrlSection alloc] initWithSectionName:@"Western New York" sectionAbbr:@"WNY" country:usa] autorelease]];
        
        [tmpSections addObject:[[[QEArrlSection alloc] initWithSectionName:@"Delaware" sectionAbbr:@"DE" country:usa] autorelease]];
        [tmpSections addObject:[[[QEArrlSection alloc] initWithSectionName:@"Eastern Pennsylvania" sectionAbbr:@"EPA" country:usa] autorelease]];
        [tmpSections addObject:[[[QEArrlSection alloc] initWithSectionName:@"Maryland-DC" sectionAbbr:@"MDC" country:usa] autorelease]];
        [tmpSections addObject:[[[QEArrlSection alloc] initWithSectionName:@"Western Pennsylvania" sectionAbbr:@"WPA" country:usa] autorelease]];
        
        [tmpSections addObject:[[[QEArrlSection alloc] initWithSectionName:@"Alabama" sectionAbbr:@"AL" country:usa] autorelease]];
        [tmpSections addObject:[[[QEArrlSection alloc] initWithSectionName:@"Georgia" sectionAbbr:@"GA" country:usa] autorelease]];
        [tmpSections addObject:[[[QEArrlSection alloc] initWithSectionName:@"Kentucky" sectionAbbr:@"KY" country:usa] autorelease]];
        [tmpSections addObject:[[[QEArrlSection alloc] initWithSectionName:@"North Carolina" sectionAbbr:@"NC" country:usa] autorelease]];
        [tmpSections addObject:[[[QEArrlSection alloc] initWithSectionName:@"Northern Florida" sectionAbbr:@"NFL" country:usa] autorelease]];
        [tmpSections addObject:[[[QEArrlSection alloc] initWithSectionName:@"South Carolina" sectionAbbr:@"SC" country:usa] autorelease]];
        [tmpSections addObject:[[[QEArrlSection alloc] initWithSectionName:@"Southern Florida" sectionAbbr:@"SFL" country:usa] autorelease]];
        [tmpSections addObject:[[[QEArrlSection alloc] initWithSectionName:@"West Central Florida" sectionAbbr:@"WCF" country:usa] autorelease]];
        [tmpSections addObject:[[[QEArrlSection alloc] initWithSectionName:@"Tennessee" sectionAbbr:@"TN" country:usa] autorelease]];
        [tmpSections addObject:[[[QEArrlSection alloc] initWithSectionName:@"Virginia" sectionAbbr:@"VA" country:usa] autorelease]];
        [tmpSections addObject:[[[QEArrlSection alloc] initWithSectionName:@"Puerto Rico" sectionAbbr:@"PR" country:usa] autorelease]];
        [tmpSections addObject:[[[QEArrlSection alloc] initWithSectionName:@"Virgin Islands" sectionAbbr:@"VI" country:usa] autorelease]];
        
        [tmpSections addObject:[[[QEArrlSection alloc] initWithSectionName:@"Arkansas" sectionAbbr:@"AR" country:usa] autorelease]];
        [tmpSections addObject:[[[QEArrlSection alloc] initWithSectionName:@"Louisiana" sectionAbbr:@"LA" country:usa] autorelease]];
        [tmpSections addObject:[[[QEArrlSection alloc] initWithSectionName:@"Mississippi" sectionAbbr:@"MS" country:usa] autorelease]];
        [tmpSections addObject:[[[QEArrlSection alloc] initWithSectionName:@"New Mexico" sectionAbbr:@"NM" country:usa] autorelease]];
        [tmpSections addObject:[[[QEArrlSection alloc] initWithSectionName:@"North Texas" sectionAbbr:@"NTX" country:usa] autorelease]];
        [tmpSections addObject:[[[QEArrlSection alloc] initWithSectionName:@"Oklahoma" sectionAbbr:@"OK" country:usa] autorelease]];
        [tmpSections addObject:[[[QEArrlSection alloc] initWithSectionName:@"South Texas" sectionAbbr:@"STX" country:usa] autorelease]];
        [tmpSections addObject:[[[QEArrlSection alloc] initWithSectionName:@"West Texas" sectionAbbr:@"WTX" country:usa] autorelease]];
        
        [tmpSections addObject:[[[QEArrlSection alloc] initWithSectionName:@"East Bay" sectionAbbr:@"EB" country:usa] autorelease]];
        [tmpSections addObject:[[[QEArrlSection alloc] initWithSectionName:@"Los Angeles" sectionAbbr:@"LAX" country:usa] autorelease]];
        [tmpSections addObject:[[[QEArrlSection alloc] initWithSectionName:@"Orange" sectionAbbr:@"ORG" country:usa] autorelease]];
        [tmpSections addObject:[[[QEArrlSection alloc] initWithSectionName:@"Santa Barbara" sectionAbbr:@"SB" country:usa] autorelease]];
        [tmpSections addObject:[[[QEArrlSection alloc] initWithSectionName:@"Santa Clara Valley" sectionAbbr:@"SCV" country:usa] autorelease]];
        [tmpSections addObject:[[[QEArrlSection alloc] initWithSectionName:@"San Diego" sectionAbbr:@"SDG" country:usa] autorelease]];
        [tmpSections addObject:[[[QEArrlSection alloc] initWithSectionName:@"San Francisco" sectionAbbr:@"SF" country:usa] autorelease]];
        [tmpSections addObject:[[[QEArrlSection alloc] initWithSectionName:@"San Joaquin Valley" sectionAbbr:@"SJV" country:usa] autorelease]];
        [tmpSections addObject:[[[QEArrlSection alloc] initWithSectionName:@"Sacramento Valley" sectionAbbr:@"SV" country:usa] autorelease]];
        [tmpSections addObject:[[[QEArrlSection alloc] initWithSectionName:@"Pacific" sectionAbbr:@"PAC" country:usa] autorelease]];
        
        [tmpSections addObject:[[[QEArrlSection alloc] initWithSectionName:@"Arizona" sectionAbbr:@"AZ" country:usa] autorelease]];
        [tmpSections addObject:[[[QEArrlSection alloc] initWithSectionName:@"Eastern Washington" sectionAbbr:@"EWA" country:usa] autorelease]];
        [tmpSections addObject:[[[QEArrlSection alloc] initWithSectionName:@"Idaho" sectionAbbr:@"ID" country:usa] autorelease]];
        [tmpSections addObject:[[[QEArrlSection alloc] initWithSectionName:@"Montana" sectionAbbr:@"MT" country:usa] autorelease]];
        [tmpSections addObject:[[[QEArrlSection alloc] initWithSectionName:@"Nevada" sectionAbbr:@"NV" country:usa] autorelease]];
        [tmpSections addObject:[[[QEArrlSection alloc] initWithSectionName:@"Oregon" sectionAbbr:@"OR" country:usa] autorelease]];
        [tmpSections addObject:[[[QEArrlSection alloc] initWithSectionName:@"Utah" sectionAbbr:@"UT" country:usa] autorelease]];
        [tmpSections addObject:[[[QEArrlSection alloc] initWithSectionName:@"Western Washington" sectionAbbr:@"WWA" country:usa] autorelease]];
        [tmpSections addObject:[[[QEArrlSection alloc] initWithSectionName:@"Wyoming" sectionAbbr:@"WY" country:usa] autorelease]];
        [tmpSections addObject:[[[QEArrlSection alloc] initWithSectionName:@"Alaska" sectionAbbr:@"AK" country:usa] autorelease]];
        
        [tmpSections addObject:[[[QEArrlSection alloc] initWithSectionName:@"Michigan" sectionAbbr:@"MI" country:usa] autorelease]];
        [tmpSections addObject:[[[QEArrlSection alloc] initWithSectionName:@"Ohio" sectionAbbr:@"OH" country:usa] autorelease]];
        [tmpSections addObject:[[[QEArrlSection alloc] initWithSectionName:@"West Virginia" sectionAbbr:@"WV" country:usa] autorelease]];
        
        [tmpSections addObject:[[[QEArrlSection alloc] initWithSectionName:@"Illinois" sectionAbbr:@"IL" country:usa] autorelease]];
        [tmpSections addObject:[[[QEArrlSection alloc] initWithSectionName:@"Indiana" sectionAbbr:@"IN" country:usa] autorelease]];
        [tmpSections addObject:[[[QEArrlSection alloc] initWithSectionName:@"Wisconsin" sectionAbbr:@"WI" country:usa] autorelease]];
        
        [tmpSections addObject:[[[QEArrlSection alloc] initWithSectionName:@"Colorado" sectionAbbr:@"CO" country:usa] autorelease]];
        [tmpSections addObject:[[[QEArrlSection alloc] initWithSectionName:@"Iowa" sectionAbbr:@"IA" country:usa] autorelease]];
        [tmpSections addObject:[[[QEArrlSection alloc] initWithSectionName:@"Kansas" sectionAbbr:@"KS" country:usa] autorelease]];
        [tmpSections addObject:[[[QEArrlSection alloc] initWithSectionName:@"Minnesota" sectionAbbr:@"MN" country:usa] autorelease]];
        [tmpSections addObject:[[[QEArrlSection alloc] initWithSectionName:@"Missouri" sectionAbbr:@"MO" country:usa] autorelease]];
        [tmpSections addObject:[[[QEArrlSection alloc] initWithSectionName:@"Nebraska" sectionAbbr:@"NE" country:usa] autorelease]];
        [tmpSections addObject:[[[QEArrlSection alloc] initWithSectionName:@"North Dakota" sectionAbbr:@"ND" country:usa] autorelease]];
        [tmpSections addObject:[[[QEArrlSection alloc] initWithSectionName:@"South Dakota" sectionAbbr:@"SD" country:usa] autorelease]];
        
        [tmpSections addObject:[[[QEArrlSection alloc] initWithSectionName:@"Maritime" sectionAbbr:@"MAR" country:canada] autorelease]];
        [tmpSections addObject:[[[QEArrlSection alloc] initWithSectionName:@"Newfoundland/Labrador" sectionAbbr:@"NL" country:canada] autorelease]];
        [tmpSections addObject:[[[QEArrlSection alloc] initWithSectionName:@"Quebec" sectionAbbr:@"QC" country:canada] autorelease]];
        [tmpSections addObject:[[[QEArrlSection alloc] initWithSectionName:@"Ontario" sectionAbbr:@"ON" country:canada] autorelease]];
        [tmpSections addObject:[[[QEArrlSection alloc] initWithSectionName:@"Manitoba" sectionAbbr:@"MB" country:canada] autorelease]];
        [tmpSections addObject:[[[QEArrlSection alloc] initWithSectionName:@"Saskatchewan" sectionAbbr:@"SK" country:canada] autorelease]];
        [tmpSections addObject:[[[QEArrlSection alloc] initWithSectionName:@"Alberta" sectionAbbr:@"AB" country:canada] autorelease]];
        [tmpSections addObject:[[[QEArrlSection alloc] initWithSectionName:@"British Columbia" sectionAbbr:@"BC" country:canada] autorelease]];
        [tmpSections addObject:[[[QEArrlSection alloc] initWithSectionName:@"Northern Territories" sectionAbbr:@"NT" country:canada] autorelease]];
        
        sections = [[NSArray alloc] initWithArray:tmpSections];
        [tmpSections release];
        
        
        NSMutableArray *tmpCategories = [[NSMutableArray alloc] init];
        
        [tmpCategories addObject:[[[QEContestCategory alloc] initWithDesignation:@"Q" categoryDescription:@"Single Op QRP"] autorelease]];
        [tmpCategories addObject:[[[QEContestCategory alloc] initWithDesignation:@"A" categoryDescription:@"Single Op Low"] autorelease]];
        [tmpCategories addObject:[[[QEContestCategory alloc] initWithDesignation:@"B" categoryDescription:@"Single Op High"] autorelease]];
        [tmpCategories addObject:[[[QEContestCategory alloc] initWithDesignation:@"U" categoryDescription:@"Single Unlimited"] autorelease]];
        [tmpCategories addObject:[[[QEContestCategory alloc] initWithDesignation:@"S" categoryDescription:@"School Club"] autorelease]];
        [tmpCategories addObject:[[[QEContestCategory alloc] initWithDesignation:@"M" categoryDescription:@"Multioperator"] autorelease]];
        
        categories = [[NSArray alloc] initWithArray:tmpCategories];
        [tmpCategories release];
    } // if
} // initialize


+ (BOOL)isSectionAbbr:(NSString *)src
{
    BOOL result = NO;
    NSEnumerator *sectionsEnum = [sections objectEnumerator];
    QEArrlSection *section;
    
    while (nil != (section = [sectionsEnum nextObject])) {
        if ([[section sectionAbbr] isEqual:src]) {
            result = true;
            break;
        } // if
    } // while
    
    return result;
} // isSectionAbbr:


+ (QEArrlSection *)sectionWithAbbr:(NSString *)abbr
{
    QEArrlSection *result = nil;
 
    NSEnumerator *e = [sections objectEnumerator];
    QEArrlSection *section;
    while (nil != (section = [e nextObject])) {
        if ([[section sectionAbbr] isEqual:abbr]) {
            result = section;
            break;
        } // if
    } // while
    
    return result;
} // sectionWithAbbr:


+ (BOOL)isCategoryDesignation:(NSString *)src
{
    BOOL result = NO;
    NSEnumerator *categoriesEnum = [categories objectEnumerator];
    QEContestCategory *category;
    
    while (nil != (category = [categoriesEnum nextObject])) {
        if ([[category designation] isEqual:src]) {
            result = true;
            break;
        } // if
    } // while
    
    return result;
} // isCategoryDesignation:


+ (QEContestCategory *)categoryWithDesignation:(NSString *)designation
{
    QEContestCategory *result = nil;
    NSEnumerator *e = [categories objectEnumerator];
    QEContestCategory *cat;
    
    while (nil != (cat = [e nextObject])) {
        if ([[cat designation] isEqual:designation]) {
            result = cat;
            break;
        } // if
    } // while
    
    return result;
} // categoryWithDesignation:


- (NSArray *)allSections
{
   // NSLog(@"MESSAGE: %s", __PRETTY_FUNCTION__);
    return sections;
} // allSections


- (NSArray *)sectionNameSortDescriptors
{
    NSSortDescriptor *sectionNameDescriptor = [[[NSSortDescriptor alloc] initWithKey:@"sectionName"
                                                                           ascending:YES] autorelease];
    return [NSArray arrayWithObject:sectionNameDescriptor];
} // sectionNameSortDescriptors


- (NSArray *)allCategories
{
   // NSLog(@"MESSAGE: %s", __PRETTY_FUNCTION__);
    return categories;
} // allCategories
@end
